package com.boot.cluster.test;

import com.boot.cluster.worker.bean.TaskSplitterInfo;
import com.boot.cluster.worker.runner.Work;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;


public class PiWork implements Work {
	private static Logger logger = LoggerFactory.getLogger(PiWork.class);

	@Override
	public <T> T action(Map<String, Object> param, TaskSplitterInfo info) {
		Double pi = 0.0d;
		for (double i = info.getStart(); i < info.getEnd(); i++) {
			pi += Math.pow(-1, i + 1) / ((2 * i) - 1);
		}
		logger.info("PiWork res:{}", pi);
		return (T) pi;
	}

}
